package io.yizoo.system.controller;

import io.elm.core.CoreController;
import io.yizoo.system.entity.sys_dict_data;
import io.yizoo.system.entity.sys_dict_type;
import io.yizoo.system.entity.sys_role;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.EnumSet;
import java.util.List;

@RestController
@RequestMapping("/system/dict")
public class dictController extends CoreController {

    @Override
    protected void Init() {
        PowerEntity =sys_dict_data.class;
        PowerUse = EnumSet.of(Power.IDDelete, Power.IDAny, Power.IDGetSingle,Power.IDUpsert);
    }

    @PostMapping("/GetData")
    public Object GetData(@RequestBody String jsonStr) {
        List<?> ret = Ctor.CoreMapper.USelect(
                Ctor.DMaker(jsonStr).Selector
                        .Select("a.*, b.dict_name")
                        .From(sys_dict_data.class, "a")
                        .LeftJoin(sys_dict_type.class, "b", "a.dict_type = b.dict_type")
                        .IsWhere("and a.dict_type = #{dict_type}","dict_type")
                        .IsWhere("and a.dict_label = #{dict_label}","dict_label")
                        .OrderBy("a.dict_type, a.dict_sort")
                        .IsPage()
                        .GetFactor());
        return JsonResultPage(ret);
    }

}
